package com.example.it.looker.view.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.it.looker.R;
import com.example.it.looker.model.entity.News;
import com.example.it.looker.utils.L;
import com.example.it.looker.view.BaseLoopViewPageAdapter;

import java.util.List;

/**
 * Created by 鲁迅认识的那只猹 on 9/4/2017 3:15 PM.
 * Emial 1258730808@qq.com
 * Desc:
 */

/**
 * 用于显示新闻的 ViewPager 的适配器，继承自 BaseLoopViewPageAdapter
 */
public class NewsPagerAdapter extends BaseLoopViewPageAdapter<News> {
    public NewsPagerAdapter(Context context, List<News> dataSource, int resId) {
        super(context, dataSource, resId);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        L.i("ViewPager" + position);
        View view = View.inflate(getContext(), getResId(), null);
        ImageView iv = (ImageView) view.findViewById(R.id.page_iv_news);
        TextView tv = (TextView) view.findViewById(R.id.page_tv_newsTitle);

        News news = getItemData(position);
        Glide.with(getContext()).load(news.getImgUrl()).into(iv);
        tv.setText(news.getTitle());

        container.addView(view);
        return view;
    }
}
